import java.util.ArrayList;
import java.util.List;

/**
 * @modulename LoadMap
 * @description This class represents the symbol table for the Linker
 * @callsequence The LoadMap is a static class, so each call to a LoadMap class will adjust
 * the overall LoadMap representation.
 * @inparam none
 * @outparam none
 * @errorstested See JUnit test cases
 * @errorsgenerated See errata report
 * @author Joe White (Jamie Trefzger)
 * @createdate 11/19/09
 * @modlog <p>
 *         <ul>
 *         Who/When/Why
 *         <li>Jamie - 11/19 - Created
 *         <li>Travis - 11/21 - Changed name to LoadMap to differentiate from Symbol table
 *         <li>Joe - 11/24 - Finished Implementing LoadMap
 *         <li>Travis - 11/29 - Added <code>symbolIsDefined</code> method
 *         </ul>
 *         <p>
 *         Coding Standards Met: "Signed Code Leader(Jaron)"
 *         <p>
 *         Testing Standards Met: "Signed Test Leader(Jamie)"
 */
public class LoadMap {
	/**
	 * @modulename infoMapLine
	 * @description This internal class is a record of the information for
	 * each symbol in the LoadMap.
	 * @callsequence infoMapLine.type<p>
	 * infoMapLine.assemblerLocation<p>
	 * infoMapLine.length<p>
	 * infoMapLine.linkerLocation<p>
	 * infoMapLine.adjustment<p>
	 * @inparam none
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White (Jamie Trefzger)
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	private static class infoMapLine {
		public  String type;
		public  String assemblerLocation;
		public  String length;
		public  String linkerLocation;
		public  String adjustment;

		public infoMapLine(){
			type = "";
			assemblerLocation = "";
			length = "";
			linkerLocation = "";
			adjustment = "";

		}

	}
	private static List<String> symbolList; 

	private static List<infoMapLine> infoList;
	
	private LoadMap() {}
	
	/**
	 * @modulename initialize.
	 * @description This method initializes the LoadMap to its initial values.
	 * @callsequence <code>LoadMap.initialize();</code>
	 * @inparam none
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Travis Casper
	 * @createdate 11/29/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Travis - 11/29 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void initialize() {
		symbolList = new ArrayList<String>(0); 
		infoList = new ArrayList<infoMapLine>(0);
	}

	/**
	 * @modulename addSymbol.
	 * @description This method initializes the LoadMap to its initial values.
	 * @callsequence <code>LoadMap.addSymbol(symbol, type, assemblerLocation, length, linkerLocation, adjustment);</code>
	 * @inparam symbol - A String that represents the symbol to be added<p>
	 * type - A String that represents the type of the symbol to be added<p>
	 * assemblerLocation - A String that represents the Assembler Assigned Location of the symbol to be added<p>
	 * length - A String that represents the length of the symbol to be added<p>
	 * linkerLocation - A String that represents the Linker Assigned Location of the symbol to be added<p>
	 * adjustment - A String that represents the symbol to be added<p>
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void addSymbol(String symbol, String type, String assemblerLocation, String length, String linkerLocation, String adjustment) {
		infoMapLine iline = new infoMapLine(); 

		iline.type = type;
		iline.assemblerLocation = assemblerLocation;
		iline.length = length;
		iline.linkerLocation = linkerLocation;
		iline.adjustment = adjustment;
		symbolList.add(symbol);
		infoList.add(iline);

	}

	/**
	 * @modulename returnSymbol.
	 * @description This method returns the symbol for the given index.
	 * @callsequence <code>LoadMap.returnSymbol(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnSymbol(int index){

		String symbol = "";
		symbol = symbolList.get(index);
		return symbol;

	}

	/**
	 * @modulename returnType.
	 * @description This method returns the type for the given symbol.
	 * @callsequence <code>LoadMap.returnType(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam String - The Type of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnType(String symbol){

		int index = 0;

		index = symbolList.indexOf(symbol);
		infoMapLine iline = new infoMapLine();
		iline = infoList.get(index);

		return iline.type;


	}
	
	/**
	 * @modulename returnType.
	 * @description This method returns the type for the given index.
	 * @callsequence <code>LoadMap.returnType(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam String - The Type of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnType(int index){

		infoMapLine iline = new infoMapLine(); 
		iline = infoList.get(index);
		return iline.type;
	}

	/**
	 * @modulename returnAssemblerLocation.
	 * @description This method returns the type for the given symbol.
	 * @callsequence <code>LoadMap.returnAssemblerLocation(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam String - The Assembler Location of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnAssemblerLocation(String symbol){

		int index = 0;

		index = symbolList.indexOf(symbol);
		infoMapLine iline = new infoMapLine();
		iline = infoList.get(index);

		return iline.assemblerLocation;
	}
	/**
	 * @modulename returnAssemblerLocation.
	 * @description This method returns the Assembler Location for the given index.
	 * @callsequence <code>LoadMap.returnAssembler Location(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam String - The Assembler Location of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnAssemblerLocation(int index){

		infoMapLine iline = new infoMapLine(); 
		iline = infoList.get(index);
		return iline.assemblerLocation;
	}

	/**
	 * @modulename returnType.
	 * @description This method returns the type for the given symbol.
	 * @callsequence <code>LoadMap.returnType(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam String - The Length of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnLength(String symbol){

		int index = 0;

		index = symbolList.indexOf(symbol);
		infoMapLine iline = new infoMapLine();
		iline = infoList.get(index);

		return iline.length;
	}
	/**
	 * @modulename returnLength.
	 * @description This method returns the Length for the given index.
	 * @callsequence <code>LoadMap.returnLength(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam String - The Length of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnLength(int index){

		infoMapLine iline = new infoMapLine(); 
		iline = infoList.get(index);
		return iline.length;
	}	

	/**
	 * @modulename returnLinkerLocation.
	 * @description This method returns the Linker Location for the given symbol.
	 * @callsequence <code>LoadMap.returnLinker Location(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam String - The Linker Location of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnLinkerLocation(String symbol) {

		int index = 0;

		index = symbolList.indexOf(symbol);
		infoMapLine iline = new infoMapLine();
		iline = infoList.get(index);

		return iline.linkerLocation; 
	}
	/**
	 * @modulename returnLinkerLocation.
	 * @description This method returns the LinkerLocation for the given index.
	 * @callsequence <code>LoadMap.returnLinkerLocation(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam String - The Linker Location of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnLinkerLocation(int index) {

		infoMapLine iline = new infoMapLine(); 
		iline = infoList.get(index);
		return iline.linkerLocation;
	}

	/**
	 * @modulename returnAdjustment.
	 * @description This method returns the Adjustment for the given symbol.
	 * @callsequence <code>LoadMap.returnAdjustment(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam String - The Adjustment of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnAdjustment (String symbol) {

		int index = 0;

		index = symbolList.indexOf(symbol);
		infoMapLine iline = new infoMapLine();
		iline = infoList.get(index);

		return iline.adjustment ;
	}
	
	/**
	 * @modulename returnAdjustment.
	 * @description This method returns the Adjustment for the given index.
	 * @callsequence <code>LoadMap.returnAdjustment(index)</code>
	 * @inparam int - The index of the desired symbol.
	 * @outparam String - The Adjustment of the desired symbol.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnAdjustment(int index) {

		infoMapLine iline = new infoMapLine(); 
		iline = infoList.get(index);
		return iline.adjustment;
	}
	
	/**
	 * @modulename symbolIsDefined.
	 * @description This method returns true iff the given symbol is 
	 * in the LoadMap.
	 * @callsequence <code>LoadMap.symbolIsDefined(symbol)</code>
	 * @inparam String - The symbol whose information is desired.
	 * @outparam boolean - Returns true iff the given symbol is defined
	 * in the LoadMap.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static boolean symbolIsDefined(String symbol) {
		return symbolList.contains(symbol);
	}

	/**
	 * @modulename size.
	 * @description This method returns the size of the LoadMap, which is
	 * equal to the number of symbols in the LoadMap
	 * @callsequence <code>LoadMap.size</code>
	 * @inparam none.
	 * @outparam int - The number of elements in the LoadMap.
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Joe White
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Joe - 11/24 - Created.
	 *         </ul>
	 *         <p>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static int size(){

		if( infoList.size() != symbolList.size()) {

			System.out.println("The number of Symbols and InfoLines do not match");
			return -1;
		}
		else{
			int size = 0;
			size = infoList.size();
			return size;
		}

	}
}	
